package com.rrd.itext.xmlBean.converter;

import com.rrd.itext.xmlBean.layoutBean.XmlText;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class XmlTextConverter implements Converter {
    public void marshal(Object obj, HierarchicalStreamWriter writer, MarshallingContext context) {
    }

	@Override
	public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
	    XmlText xmlText = new XmlText();
        xmlText.setName(reader.getAttribute("name"));
        String text = reader.getValue();
        xmlText.setText(text);
        return xmlText;
    }

    public boolean canConvert(Class clazz) {
        return clazz.equals(XmlText.class);
    }
}
